﻿using CKEditor.NET;
using Portal.Api;
using System.Web;

/// <summary>
/// Configures basic settings for the CKEditor.
/// </summary>
public class CKEditorConfigurator
{
  CKEditorControl _EditorControl;

	public CKEditorConfigurator(CKEditorControl EditorControl)
	{
    _EditorControl = EditorControl;

    // Filemanager Configuration.
    string ConnectorUrl = "Connector=" + Config.GetAbsoluteUrl() + "js/CKEditor/filemanager/connectors/aspx/connector.aspx";
    _EditorControl.FilebrowserBrowseUrl = "js/CKEditor/filemanager/browser/default/browser.html?" + ConnectorUrl;
    _EditorControl.FilebrowserImageBrowseUrl = "js/CKEditor/filemanager/browser/default/browser.html?Type=Image&" + ConnectorUrl;
    _EditorControl.FilebrowserFlashBrowseUrl = "js/CKEditor/filemanager/browser/default/browser.html?Type=Flash&" + ConnectorUrl;
    _EditorControl.ContentsCss = Portal.Helper.CssEditPath;
    // Allow to upload files to the server.
    HttpContext.Current.Session["CanUploadFiles"] = true;
	}

  public void ConfigureToolbarInplace()
  {
    _EditorControl.config.toolbar = new object[]
    {
      new object[] { "Maximize", "-", "Source"},
      new object[] { "Cut","Copy","Paste","PasteText","PasteFromWord","-", "SpellChecker", "Scayt"},
      new object[] { "Undo","Redo","-","Find","Replace","-","SelectAll","RemoveFormat"},
      new object[] { "Form", "Checkbox", "Radio", "TextField", "Textarea", "Select", "Button", "ImageButton", "HiddenField"},
      new object[] { "Bold","Italic","Underline","Strike","-","Subscript","Superscript"},
      new object[] { "NumberedList","BulletedList","-","Outdent","Indent","Blockquote","CreateDiv"},
      new object[] { "JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"},
      new object[] { "Link","Unlink","Anchor"},
      new object[] { "Image","Flash","Table","HorizontalRule","Smiley","SpecialChar","PageBreak","Iframe"},
      new object[] { "Styles","Format","Font","FontSize"},
      new object[] { "TextColor","BGColor"},
      new object[] { "ShowBlocks","-","About"}
    };
  }

  public void ConfigureToolbarInplaceNoForm()
  {
    _EditorControl.config.toolbar = new object[]
    {
      new object[] { "Maximize", "-", "Source"},
      new object[] { "Cut","Copy","Paste","PasteText","PasteFromWord","-", "SpellChecker", "Scayt"},
      new object[] { "Undo","Redo","-","Find","Replace","-","SelectAll","RemoveFormat"},  
      new object[] { "Bold","Italic","Underline","Strike","-","Subscript","Superscript"},
      new object[] { "NumberedList","BulletedList","-","Outdent","Indent","Blockquote","CreateDiv"},
      new object[] { "JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"},
      new object[] { "Link","Unlink","Anchor"},
      new object[] { "Image","Flash","Table","HorizontalRule","Smiley","SpecialChar","PageBreak","Iframe"},
      new object[] { "Styles","Format","Font","FontSize"},
      new object[] { "TextColor","BGColor"},
      new object[] { "ShowBlocks","-","About"}
    };
  }
}
